package com.zlsy.thread.jmm;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zhouliang
 * @date 2020/04/28
 **/
public class Novolatile implements Runnable {

    volatile int a;
    AtomicInteger read = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        Novolatile r = new Novolatile();
        Thread thread1 = new Thread(r);
        Thread thread2 = new Thread(r);
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();

        System.out.println(r.a);
        System.out.println("ato：" + r.read.get());
    }

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            a++;
            read.incrementAndGet();
        }
    }
}
